package org.zn.mvcbase.response;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.zn.mvcbase.response.EasyUIDataGridBean;
import org.zn.mvcbase.response.JqgridMessage;
import org.zn.mvcbase.rest.EntityBody;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;

/**
* 
* @Company OBOR
* @Author 周楠
* @Description
* 2018年11月27日
*
*/
public class Es2JqMessageUtils {
	

	public static JqgridMessage  convert(Map<String, Object> message){
		
		return null;
	
	}
	
	public static JqgridMessage convert(EasyUIDataGridBean<?> message){
		
		return null;
		
	}
	
	public static JqgridMessage convert(JsonNode  message){
		
		JsonNode row=message.get("rows");
		JsonNode total= message.get("total");
		JsonNode status= message.get("status");
		
		return null;
		
	}
	
	public static JqgridMessage convert(EntityBody  message, Integer pagesize, Integer page) throws JsonParseException, JsonMappingException, IOException{

		List<Map> rows=message.find("rows").toJavaObject(new TypeReference<List<Map>>() {});
		Long tot= message.find("total").getBodyNode().longValue();
		String status= message.find("status").getBodyNode().textValue();;
		
		Integer total= (int) ((tot/pagesize) + (tot%pagesize>0?1:0));
		
		JqgridMessage jm= new JqgridMessage(page, total, tot, rows);
		
		jm.setStatus(status);
		
		return jm;
		
		
		
	}
	
	

}
